package com.ruoyi.project.tugboat.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.tugboat.domain.CDevice;
import com.ruoyi.project.tugboat.service.ICDeviceService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 拖轮设备Controller
 * 
 * @author ruoyi
 * @date 2023-12-14
 */
@RestController
@RequestMapping("/system/device")
public class CDeviceController extends BaseController
{
    @Autowired
    private ICDeviceService cDeviceService;

    /**
     * 查询拖轮设备列表
     */
    @PreAuthorize("@ss.hasPermi('system:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(CDevice cDevice)
    {
        startPage();
        List<CDevice> list = cDeviceService.selectCDeviceList(cDevice);
        return getDataTable(list);
    }

    /**
     * 导出拖轮设备列表
     */
    @PreAuthorize("@ss.hasPermi('system:device:export')")
    @Log(title = "拖轮设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CDevice cDevice)
    {
        List<CDevice> list = cDeviceService.selectCDeviceList(cDevice);
        ExcelUtil<CDevice> util = new ExcelUtil<CDevice>(CDevice.class);
        util.exportExcel(response, list, "拖轮设备数据");
    }

    /**
     * 获取拖轮设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:device:query')")
    @GetMapping(value = "/{deviceId}")
    public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId)
    {
        return success(cDeviceService.selectCDeviceByDeviceId(deviceId));
    }

    /**
     * 新增拖轮设备
     */
    @PreAuthorize("@ss.hasPermi('system:device:add')")
    @Log(title = "拖轮设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CDevice cDevice)
    {
        return toAjax(cDeviceService.insertCDevice(cDevice));
    }

    /**
     * 修改拖轮设备
     */
    @PreAuthorize("@ss.hasPermi('system:device:edit')")
    @Log(title = "拖轮设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CDevice cDevice)
    {
        return toAjax(cDeviceService.updateCDevice(cDevice));
    }

    /**
     * 删除拖轮设备
     */
    @PreAuthorize("@ss.hasPermi('system:device:remove')")
    @Log(title = "拖轮设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deviceIds}")
    public AjaxResult remove(@PathVariable Long[] deviceIds)
    {
        return toAjax(cDeviceService.deleteCDeviceByDeviceIds(deviceIds));
    }
}
